package com.example.a2205douyin.adapter;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.a2205douyin.R;
import com.example.a2205douyin.entity.VideoEntity;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.List;

public class VideoTuiAdapter extends BaseMultiItemQuickAdapter<VideoEntity.DataBean, BaseViewHolder> {
    public VideoTuiAdapter(@Nullable List<VideoEntity.DataBean> data) {
        super(data);
        addItemType(0, R.layout.item_video_normal);//0---普通布局  1----进入直播间  2----全屏观看
        addItemType(1,R.layout.item_video_live);
        addItemType(2,R.layout.item_video_full);
        addItemType(5,R.layout.item_video_normal);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, VideoEntity.DataBean bean) {
        switch (bean.getItemType()){
            case 0:
            case 2:
            case 5:
            {
                //播放器控件
                StandardGSYVideoPlayer gsy = holder.findView(R.id.gsy);
                //设置播放资源//视频地址     是否播放时缓存     视频标题
                gsy.setUp(bean.getVideopath(),true,"");
                gsy.startPlayLogic();//开始播放视频
                gsy.getBackButton().setVisibility(View.GONE);//返回按钮  不显示

                //设置切换全屏
                gsy.setLockLand(true);
                gsy.setShowFullAnimation(true);//切换全屏显示动画效果
                gsy.setAutoFullWithSize(false);//自动全屏  关闭

                ImageView ivZhuan = holder.findView(R.id.iv_zhuan);
                ImageView ivUser = holder.findView(R.id.iv_user);
                ImageView ivDianzan = holder.findView(R.id.iv_dianzan);
                ImageView ivAdd = holder.findView(R.id.iv_add);
                Glide.with(getContext()).load(bean.getHeadpath()).circleCrop().into(ivZhuan);
                Glide.with(getContext()).load(bean.getHeadpath()).circleCrop().into(ivUser);

                holder.setText(R.id.tv_dianzan,bean.getLike_count()+"");//点赞数量
                holder.setText(R.id.tv_caption,bean.getCaption()+"");//视频标题
                holder.setText(R.id.tv_user,bean.getAuthname()+"");//博主名称

                //如果这个视频点赞过，点赞图片换成红色的，未点赞过，点赞图片是白色的
                if(bean.getDianzan()==1){
                    ivDianzan.setImageResource(R.drawable.ic_xihuanred);
                    holder.setText(R.id.tv_dianzan,bean.getLike_count()+1+"");//点赞数量
                }else {
                    ivDianzan.setImageResource(R.drawable.ic_xihuan);
                }
                //如果这个博主被关注了，关注图标不显示   如果没有被关注   关注图标显示
                if(bean.getGuanzhu()==1){
                    ivAdd.setVisibility(View.GONE);
                }else {
                    ivAdd.setVisibility(View.VISIBLE);
                }
                //让下方的图片一值旋转
                ObjectAnimator animator = ObjectAnimator.ofFloat(ivZhuan, "rotation", 0, 360);
                animator.setDuration(2000);
                animator.setRepeatCount(ValueAnimator.INFINITE);//一直
                animator.start();

            }
                break;
            case 1:
            {
                //播放器控件
                StandardGSYVideoPlayer gsy = holder.findView(R.id.gsy);
                //设置播放资源//视频地址     是否播放时缓存     视频标题
                gsy.setUp(bean.getVideopath(),true,"");
                gsy.startPlayLogic();//开始播放视频
                gsy.getBackButton().setVisibility(View.GONE);//返回按钮  不显示

                holder.setText(R.id.tv_caption,bean.getCaption()+"");//视频标题
                holder.setText(R.id.tv_user,bean.getAuthname()+"");//博主名称
            }
                break;
        }
    }
}
